package com.travel.Config;



import com.travel.util.AES;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

@Component
public class Security_PasswordEncoder implements PasswordEncoder {

    //加密秘钥是“基于SpringBoot+Vue的旅游指南的设计与实现”的MD5大写32位加密形式
    public static String secretKey = "61035B6B9317A031F9C5F3196325DF4B";

    @Override
    public String encode(CharSequence rawPassword) {
        try {

            return AES.encrypt(rawPassword.toString(),secretKey);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public boolean matches(CharSequence rawPassword, String encodedPassword) {
        String AESde = encode(rawPassword);
        return encodedPassword.equals(AESde);
    }

    public String getSecretKey() {
        return secretKey;
    }
}
